package com.icygen.eclipsetools.ui.dialogs;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.CheckboxTreeViewer;

import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.core.resources.IProject;

import com.icygen.eclipsetools.project.IcygenProjectSupport;
import com.icygen.eclipsetools.project.config.ApplicationConfig;

public class ConfigApplicationDialog extends Dialog {
	
	/*
	 * DB Settings Felds
	 */
	Text _host;
	Text _username;
	Text _password;
	Text _database;
	
	
	Button button;
	
	private IProject _project;
	private ApplicationConfig _config;
	
	public ConfigApplicationDialog(Shell parentShell, IProject project) {
	    super(parentShell);
	    
	    _project = project;
	    _config = IcygenProjectSupport.getApplicationConfig(_project);
	}
	
	@Override
	protected Control createDialogArea(Composite parent)
	{
	    Composite container = (Composite) super.createDialogArea(parent);
	    GridLayout gridLayout = new GridLayout(2, false);
	    container.setLayout(gridLayout);
	    
	    Label labelHost = new Label(container, SWT.LEFT);
	    labelHost.setText("Host: ");
	    _host = new Text(container, SWT.NONE);
	    _host.setLayoutData(new GridData(GridData.FILL_BOTH));
	    _host.setText(_config.getDevelopmentConfig().getResources().getDb().getParams().getHost());
	    
	    Label labelUsername = new Label(container, SWT.LEFT);
	    labelUsername.setText("Username: ");
	    _username = new Text(container, SWT.NONE);
	    _username.setLayoutData(new GridData(GridData.FILL_BOTH));
	    _username.setText(_config.getDevelopmentConfig().getResources().getDb().getParams().getUsername());
	    
	    Label labelPassword = new Label(container, SWT.LEFT);
	    labelPassword.setText("Password: ");
	    _password = new Text(container, SWT.NONE);
	    _password.setLayoutData(new GridData(GridData.FILL_BOTH));
	    _password.setText(_config.getDevelopmentConfig().getResources().getDb().getParams().getPassword());
	    
	    Label labelDatabase = new Label(container, SWT.LEFT);
	    labelDatabase.setText("Database: ");
	    _database = new Text(container, SWT.NONE);
	    _database.setLayoutData(new GridData(GridData.FILL_BOTH));
	    _database.setText(_config.getDevelopmentConfig().getResources().getDb().getParams().getDbname());
	  
	   

	    return container;
	}

	// overriding this methods allows you to set the
	// title of the custom dialog
	@Override
	protected void configureShell(Shell newShell) {
	    super.configureShell(newShell);
	    newShell.setText("Selection dialog");
	}

	@Override
	protected Point getInitialSize() {
	    return new Point(450, 300);
	}
}
